package weekMatch.one_348;

public class LeeCode_03 {
    public static void main(String[] args) {
        System.out.println(matrixSumQueries(3, new int[][]{{0, 0, 1}, {1, 2, 2}}));
    }

    private static long matrixSumQueries(int n, int[][] queries) {
        int r_rows = n, r_cows = n;
        int m =queries.length;
        boolean[] u_rows = new boolean[n];
        boolean[] u_cows = new boolean[n];
        long sum = 0;
        for (int i = m - 1; i>= 0; i--){
            int[] q = queries[i];
            if (q[0] == 0){
                if (r_cows == 0 || u_rows[q[1]])
                    continue;
                sum += (long) r_cows * q[2];
                u_rows[q[1]] = true;
                r_rows--;
            }else {
                if (r_rows == 0 || u_cows[q[1]])
                    continue;
                u_cows[q[1]] = true;
                sum += (long) r_rows * q[2];
                r_cows--;
            }
        }
        return sum;
    }
}
